package cn.edu.nju.oraldefense.action;

import javax.annotation.Resource;

import org.apache.struts2.json.annotations.JSON;

import cn.edu.nju.oraldefense.model.Teacher;
import cn.edu.nju.oraldefense.service.TeacherService;

import com.opensymphony.xwork2.ActionSupport;

public class TeacherAddAction extends ActionSupport {
	private Teacher teacher;
	private TeacherService teacherService;
	private boolean success;

	@JSON(serialize = false)
	public Teacher getTeacher() {
		return teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	@JSON(serialize = false)
	public TeacherService getTeacherService() {
		return teacherService;
	}

	@Resource
	public void setTeacherService(TeacherService teacherService) {
		this.teacherService = teacherService;
	}

	public String execute() {
		System.out.println(teacher);
		if (teacher != null) {
			teacher.setPassword("123456");
			teacherService.addTeacher(teacher);
			success = true;
		}
		return SUCCESS;
	}

}
